package com.sike;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射 /image/** 路径到类路径下的 /static/image/ 目录
        registry.addResourceHandler("/image/**")
                .addResourceLocations("classpath:/static/image/");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 允许所有路径、所有请求头、所有方法，且允许携带凭证
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8081")
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}
